package com.java.dormitorymanager.impl;

import com.java.dormitorymanager.dao.IManagerDao;
import com.java.dormitorymanager.pojo.Manager;
import com.java.dormitorymanager.util.BasicDao;
import org.junit.jupiter.api.Test;

import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
import java.util.List;

/**
 * @program: DormitoryManager
 * @description: IManagerDao的实现类
 * @author: ShuangChenYue
 * @create: 2021-05-14 15:50
 **/
public class ManagerDaoImpl implements IManagerDao
{

    @Override
    public Manager findByNameAndPassword(String name, String password)
    {
        return BasicDao.getObject(Manager.class,"select * from manager where name=? and password=?",name,password);
    }

    @Override
    public void addManager(Manager manager)
    {
        BasicDao.updateData("insert into manager(name,password) value(?,?)",manager.getName(),manager.getPassword());
    }

    @Override
    public List<Manager> findAll()
    {
        return BasicDao.getObjectToList(Manager.class,"select * from manager");
    }

    @Override
    public List<Manager> findAllSuperManager()
    {
        return BasicDao.getObjectToList(Manager.class, "select * from manager where status='super'");
    }

    @Override
    public Manager findManagerById(int id)
    {
        return BasicDao.getObject(Manager.class,"select * from manager where id=?",id);
    }

    @Override
    public void updateSuperManager(Manager manager)
    {
        BasicDao.updateData("update manager set name=?,password=? where id=?",manager.getName(),manager.getPassword(),manager.getId());
    }

    @Override
    public List<Manager> findAllCommonManager()
    {
        return BasicDao.getObjectToList(Manager.class,"select * from manager where status='common'");
    }

    @Override
    public void deleteCommonManagerById(int id)
    {
        BasicDao.updateData("delete from manager where id=?",id);
    }

    @Override
    public void updateCommonManager(Manager manager)
    {
        BasicDao.updateData("update manager set name=?,password=?,status=? where id=?",manager.getName(),manager.getPassword(),manager.getStatus(),manager.getId());
    }

    @Override
    public void addCommonManager(Manager manager)
    {
        BasicDao.updateData("insert into manager(name,password) value(?,?)",manager.getName(),manager.getPassword());
    }

    @Override
    public Manager findCommonManagerByName(String name)
    {
        return BasicDao.getObject(Manager.class,"select * from manager where status='common' and name=?",name);
    }

    @Override
    public void updateCommonManagerStatusToZero(int id)
    {
        BasicDao.updateData("update manager set status='NO' where id=?",id);
    }

    @Override
    public List<Manager> findAllBannedManager()
    {
        return BasicDao.getObjectToList(Manager.class,"select * from manager where status='NO'");
    }

    @Override
    public void deleteBannedManagerById(int id)
    {
        BasicDao.updateData("delete from manager where id=?",id);
    }

    @Override
    public void openBannedManagerById(int id)
    {
        BasicDao.updateData("update manager set status='common' where id=?",id);
    }

    @Override
    public List<Manager> findAllDormManager()
    {
        return BasicDao.getObjectToList(Manager.class,"select * from manager where status='common'");
    }
}
